package com.lc.reader.data.database

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import android.content.Context
import com.lc.reader.data.dao.BookDao
import com.lc.reader.data.dao.BookmarkDao
import com.lc.reader.data.model.Book
import com.lc.reader.data.model.Bookmark

@Database(
    entities = [Book::class, Bookmark::class],
    version = 1,
    exportSchema = false
)
abstract class ReaderDatabase : RoomDatabase() {
    
    abstract fun bookDao(): BookDao
    abstract fun bookmarkDao(): BookmarkDao
    
    companion object {
        @Volatile
        private var INSTANCE: ReaderDatabase? = null
        
        fun getDatabase(context: Context): ReaderDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    ReaderDatabase::class.java,
                    "reader_database"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }
}
